package com.yanqu.road.server.cmd.banquet.party;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.banquet.CrossPartyMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = CrossProtocol.C_CROSS_PARTY_JOIN, desc = "")
public class CrossJoinPartyCmd extends CrossCommand {
    private long userId;
    private String partyId;
    private UserBaseInfo userBaseInfo;
    private int gitfId;
    private long popularity;
    private long integral;
    private String consume;
    private int giftAcceptState;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BanquetProto.CrossJoinPartyReqMsg req = BanquetProto.CrossJoinPartyReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        partyId = req.getPartyId();
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(req.getPlayerBaseData());
        gitfId = req.getGiftId();
        popularity = req.getPopularity();
        integral = req.getIntegral();
        consume = req.getConsume();
        giftAcceptState = req.getGiftAcceptState();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BanquetProto.CrossJoinPartyRespMsg.Builder msg = CrossPartyMgr.joinParty(partyId, serverId, userId, userBaseInfo, gitfId, popularity, integral, giftAcceptState);
        msg.setConsume(consume);
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_PARTY_JOIN_RESULT, msg);
        MessageHelper.sendPacket(serverId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
